﻿using System.Configuration;

namespace ASPNETVN.PORTAL.Components.Configuration.Items
{
    public sealed class DomainElement : ConfigurationElement
    {
        [ConfigurationProperty("domainName", IsRequired = true)]
        public string DomainName
        {
            get { return (string)this["domainName"]; }
            set { this["domainName"] = value; }
        }

        [ConfigurationProperty("domainUrl", IsRequired = true)]
        public string DomainUrl
        {
            get { return (string)this["domainUrl"]; }
            set { this["domainUrl"] = value; }
        }
    }

    public sealed class DomainCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new DomainElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((DomainElement)element).DomainName;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName
        {
            get
            {
                return "domain";
            }
        }
    }

    public class DomainsSection : ConfigurationSection
    {
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public DomainCollection Domains
        {
            get
            {
                return (DomainCollection)base[""];
            }
        }
    }

    public class DomainConfigurationHandler : ConfigurationSection
    {
        [ConfigurationProperty("DomainName")]
        public string DomainName
        {
            get
            {
                return this["domainName"].ToString();
            }
            set
            {
                this["domainName"] = value;
            }
        }

        [ConfigurationProperty("DomainUrl")]
        public string DomainUrl
        {
            get
            {
                return this["domainUrl"].ToString();
            }
            set
            {
                this["domainUrl"] = value;
            }
        }
    }
}
